package club.ruanx.movie.repository;


import club.ruanx.core.repository.base.BaseRepository;
import club.ruanx.movie.entity.Movie;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author 阮胜
 * @date 2018/10/21 20:16
 */
public interface MovieRepository extends BaseRepository<Movie, String> {

    List<Movie> findByIdIn(String... ids);

    Page<Movie> findAllByOrderByRateDesc(Pageable pageable);

    Page<Movie> findAllByOrderByCreateTimeDesc(Pageable pageable);

    @Query(value = "SELECT * FROM t_movie WHERE JSON_CONTAINS(TYPES,JSON_ARRAY(:typeId))", nativeQuery = true)
    Page<Movie> findAllByType(@Param("typeId") Integer typeId, Pageable pageable);

    boolean existsBySpiderId(String spiderId);

    Page<Movie> findAllByActorsContainingOrDirectorsContaining(String actor, String director,Pageable pageable);
}
